const express = require('express')
var bodyParser = require('body-parser');
const { response } = require('express');
const app = express()
const moment = require('moment');
app.use(bodyParser.json())
app.all("*", function (req, res, next) {
  //设置允许跨域的域名，*代表允许任意域名跨域
  res.header("Access-Control-Allow-Origin", req.headers.origin || '*');
  // //允许的header类型
  res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With");
  // //跨域允许的请求方式 
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  // 可以带cookies
  res.header("Access-Control-Allow-Credentials", true);
  if (req.method == 'OPTIONS') {
    res.sendStatus(200);
  } else {
    next();
  }
})
let a = { "index": "0", "duration": 0 }
// 查询当前播放状态
app.get('/getStatus', (request, response) => {
  response.status('200').json(a)
})
app.get('/setStatus', (request, response) => {
  a = JSON.parse(request.query.status)
  response.status('200').json('1')
})

app.listen(8889, () => {
  console.log('服务启动>> 端口号为：8889')
})
